<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<!-- <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix"> -->
					<view class="avatars">
						<view class="logo">{{nickname.slice(-2)}}</view>
					</view>
					</image>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" @click="handleToInfo" class="user-info">
						<view class="u_title">
							{{ nickname }}
						</view>
						<view class="u_title">
							{{ name }}
						</view>
						<view class="u_title" style="font-size: 16px;">
							版本号：1.1.1.4
						</view>
					</view>
				</view>
				<!--    <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right"></view>
        </view> -->
			</view>
		</view>

		<view class="content-section">
			<!--      <view class="mine-actions grid col-4 text-center">
        <view class="action-item" @click="handleJiaoLiuQun">
          <view class="iconfont icon-friendfill text-pink icon"></view>
          <text class="text">交流群</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-service text-blue icon"></view>
          <text class="text">在线客服</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-community text-mauve icon"></view>
          <text class="text">反馈社区</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-dianzan text-green icon"></view>
          <text class="text">点赞我们</text>
        </view>
      </view> -->

			<view class="menu-list">
				<!-- <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <view class="iconfont icon-user menu-icon"></view>
            <view>编辑资料</view>
          </view>
        </view> -->
				<view class="list-cell list-cell-arrow" @click="handleHelp">
					<view class="menu-item-box">
						<view class="iconfont icon-help menu-icon"></view>
						<view>用户协议</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleAbout">
					<view class="menu-item-box">
						<view class="iconfont icon-aixin menu-icon"></view>
						<view>隐私政策</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" style="display: flex;">
					<view class="menu-item-box" style="width: 35%;" @click="share_toggle($event)">
						<view class="iconfont icon-setting menu-icon"></view>
						<view>手写签名</view>
					</view>
					<view @click="y_l(sxqm_path)" v-if="sxqm_path">
						<image :src="sxqm_path" mode="aspectFill" style="width: 360rpx;height: 120rpx;"></image>
					</view>
				</view>
				<view class="cu-list menu" style="margin-top: 50%;">
					<view class="cu-item item-box">
						<view class="content text-center" @click="handleLogout">
							<text class="text-black">退出登录</text>
						</view>
					</view>
				</view>
			</view>

		</view>
		<view>
			<uni-popup ref="share" type="bottom" safeArea backgroundColor="#fff" style="width: 100% ;height: 100%;">
				<view style="width: 750rpx ;height: 750rpx;background-color: #fff;">
					<l-signature disableScroll v-if="share_open" ref="signatureRef" :beforeDelay="100"
						:penSize="penSize" :openSmooth="openSmooth"></l-signature>
				</view>
				<view class="sxqm_cz">
					<view class="sxqm_cz_bt" @click="onClick('close')">关闭</view>
					<view class="sxqm_cz_bt" @click="onClick('clear')">清空</view>
					<view class="sxqm_cz_bt" @click="onClick('undo')">撤消</view>
					<view class="sxqm_cz_bt" @click="onClick('save')">保存</view>
				</view>



			</uni-popup>
		</view>
		<tabBar selectedIndex=4 v-if="storage_data=='create'"></tabBar>
		<!-- 	<tabBar selectedIndex=3 v-if="storage_data=='create'"></tabBar> -->
		<tabBar selectedIndex=1 v-else></tabBar>
	</view>
</template>

<script>
	import {
		getSig
	} from '@/api/system/user.js'
	import {
		uploadBase64
	} from '@/api/system/pcqd.js'
	export default {
		data() {
			return {
				name: this.$store.state.user.name,
				storage_data: '',
				nickname: this.$store.state.user.nickname,
				share_open: false,
				penSize: 6, //线宽
				openSmooth: true, //压感
				sxqm_path: '', //手写签名返回地址
				params: {},
				data_json: '', //手写签名返回json
			}
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},

			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		onReady() {
			uni.hideTabBar() //隐藏导航栏方法
		},
		created() {
			this.storage_data = uni.getStorageSync('storage_data').user_roles[0];
			console.log('sxqm_path', this.$store.state.user.userSig)
			this.sxqm_path = 'http://192.168.1.143:8089/common/file/' + this.$store.state.user.userSig + '/previewOriginal'
		},
		onShow() {
			this.storage_data = uni.getStorageSync('storage_data').user_roles[0];
			console.log('sxqm_path', this.$store.state.user.userSig)
			this.sxqm_path = 'http://192.168.1.143:8089/common/file/' + this.$store.state.user.userSig + '/previewOriginal'
		},
		methods: {
			y_l() {
				let a = [];
				a[0] = this.sxqm_path;
				uni.previewImage({
					urls: a,
				})
			},
			handleLogout() {
				this.$modal.confirm('确定退出登录吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {}).finally(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleHelp() {
				this.$tab.navigateTo('/pages/mine/help/index')
			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			handleJiaoLiuQun() {
				this.$modal.showToast('QQ群：①133713780(满)、②146013835(满)、③189091635')
			},
			handleBuilding() {
				this.$modal.showToast('模块建设中~')
			},
			//打开手写面板
			share_toggle() {
				// let userinfo = uni.getStorageSync('user_info');
				if (this.isPC()) {
					uni.showToast({
						title: '请登录手机端设置手写签名！',
						icon: 'none'
					})
				} else {
					let signText = this.nickname
					console.log('signText', signText.length)
					if (signText.length > 3) {
						this.$refs.share.open();
						setTimeout(() => {
							this.share_open = true
						}, 100);
					} else {
						uni.navigateTo({
							url: '../../package_signature/signature/signature'
						})
					}
				}

			},
			/** 是否是pc端 */
			isPC() {
				if (["windows", "mac"].some((v) => v === uni.getStorageSync("platform"))) {
					return true;
				}
				if (Number(uni.getStorageSync("windowWidth")) > 1000) {
					return true;
				}
				return false;
			},
			//提交接口调用
			//绘制操作
			onClick(type) {
				let that = this;
				if (type == 'close') {
					that.$refs.signatureRef.clear(); //先清空画布
					that.$refs.share.close(); //再关闭面板
					return
				};
				if (type == 'openSmooth') {
					that.openSmooth = !that.openSmooth
					return
				};
				if (type == 'save') {
					that.$refs.signatureRef.canvasToTempFilePath({
						success: (res) => {
							// 是否为空画板 无签名
							if (res.isEmpty) {
								uni.showToast({
									title: '您尚未进行签名，请您签名后再次保存！',
									icon: 'none'
								})
								return
							}
							uploadBase64({
								base64: res.tempFilePath,
								bizType: 'sig'
							}).then(res => {
								console.log('res', res)
								// that.signature = res.data.id
								that.share_open = false;
								that.$refs.share.close(); //再关闭面板
								that.sxqm_path = 'http://192.168.1.143:8089/common/file/' + res.data
									.id + '/previewOriginal'
								// that.submit()
								getSig(res.data.id).then(res => {
									console.log('res', res)
									// console.log("that.$store.dispatch('GetInfo')",that.$store.dispatch('GetInfo'))
									that.$store.dispatch('GetInfo').then(res => {})
									// uni.navigateBack()
								})
							})
						}
					})
					return
				}
				if (this.$refs.signatureRef)
					this.$refs.signatureRef[type]();
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f6f7;
	}

	.avatars {
		width: 140rpx;
		height: 140rpx;
		border-radius: 50%;
		margin: 38rpx 24rpx 0 0;
		overflow: hidden;
		background-color: rgb(147, 197, 255);
	}

	.logo {
		text-align: center;
		line-height: 140rpx;
		font-size: 52rpx;
	}

	.mine-container {
		width: 100%;
		height: 100%;


		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #3c96f3;
			color: white;
			background-image: linear-gradient(-225deg, #2CD8D5 0%, #6B8DD6 48%, #8E37D7 100%);

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
				}
			}
		}

		.content-section {
			position: relative;
			// top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}
	}
</style>